package com.haihui.platform.controller.dead;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.haihui.platform.controller.BaseController;
import com.haihui.platform.entity.DeadBaseInfo;
import com.haihui.platform.service.dead.DeadBaseInfoService;
import com.haihui.platform.utils.PrimaryKeyGen;

@Controller
@RequestMapping("/deadinfo")
public class DeadBaseInfoController extends BaseController{

	private static final Logger LOG = Logger.getLogger(DeadBaseInfoController.class);
	
	@Autowired
	private DeadBaseInfoService deadBaseInfoService;
	
	/**
	 * 逝者列表
	 * @param dead
	 */
	@RequestMapping(value="/list")
	public void list(DeadBaseInfo dead){
		try{
			int count = deadBaseInfoService.count(dead);
			List<DeadBaseInfo> list = deadBaseInfoService.list(dead);
			this.responseWriter(this.getCommonJsonPage(count,list));
		}catch(Exception e){
			LOG.error(e.getMessage(),e);
			this.responseWriter(this.getCommonJsonString(false, "查询失败"));
		}
	}
	
	/**
	 * 新增逝者
	 * @param dead
	 */
	@RequestMapping(value="/add")
	public void add(DeadBaseInfo dead){
		try{
			dead.setBaseId(PrimaryKeyGen.getKey());
			int count = deadBaseInfoService.add(dead);
			this.responseWriter(this.getCommonJsonString(true, "新增成功", count));
		}catch(Exception e){
			LOG.error(e.getMessage(),e);
			this.responseWriter(this.getCommonJsonString(false, "新增失败"));
		}
	}
	
	/**
	 * 逝者信息修改
	 * @param dead
	 */
	@RequestMapping(value="/update")
	public void update(DeadBaseInfo dead){
		try{
			dead.setModifyTime(new Date());
			int count = deadBaseInfoService.update(dead);
			this.responseWriter(this.getCommonJsonString(true, "修改成功", count));
		}catch(Exception e){
			LOG.error(e.getMessage(),e);
			this.responseWriter(this.getCommonJsonString(false, "修改失败"));
		}
	}
	
	/**
	 * 逝者详情
	 * @param dead
	 */
	@RequestMapping(value="/detail")
	public void detail(DeadBaseInfo dead){
		try{
			DeadBaseInfo info = deadBaseInfoService.detail(dead);
			this.responseWriter(this.getCommonJsonString(true, "查询成功", info));
		}catch(Exception e){
			LOG.error(e.getMessage(),e);
			this.responseWriter(this.getCommonJsonString(false, "查询失败"));
		}
	}
	
	/**
	 * 删除逝者
	 * @param dead
	 */
	@RequestMapping(value="/delete")
	public void deletev(DeadBaseInfo dead){
		try{
			int count = deadBaseInfoService.delete(dead);
			this.responseWriter(this.getCommonJsonString(true, "删除成功", count));
		}catch(Exception e){
			LOG.error(e.getMessage(),e);
			this.responseWriter(this.getCommonJsonString(false, "删除失败"));
		}
	}
	
}
